#include "RandomAccess.h"

#include "Utility.h"

#include <stdio.h>

int* getTupleInFileByNumber(FILE* sourceFile, int tupleNumber, int arity)
{
    int* t = new int[arity];/*

    char* segmentName = getSegmentName(sourceRelation, segmentNumber);

    FILE* binFileIn = 
        fopen(getFileNameByRelationNameWithExtension(segmentName,"bin"),"rb");*/

    fseek(sourceFile,tupleNumber*sizeof(int)*arity,SEEK_SET);

    fread(t,sizeof(int)*arity,1,sourceFile);

    return t;
}

int getKeyInIndex(FILE* indexFile, int line)
{
    int* t = getTupleInFileByNumber(indexFile, line, 2);
    return t[0];
}

int getValueInIndex(FILE* indexFile, int line)
{
    int* t = getTupleInFileByNumber(indexFile, line, 2);
    return t[1];  
}